<?php
namespace Common\Model;

/**
 * 授权登录信息记录表
 * @modify trainyao 2016-04-27 创建
 * @index `userauth` (`type`,`oauthid`)
 */

Class UserAuthModel extends BaseModel
{
    protected $trueTableName = 'bk_user_auth';

    public function addInfo($oauthId, $type, $token, $name, $gender, $headpath, $expiretime) {
        $data = array(
            'oauthid' => $oauthId,
            'type' => $type,
            'token' => $token,
            'name' => $name,
            'gender' => $gender,
            'headpath' => $headpath,
            'expiretime' => $expiretime,
        );
        return $this->add($data) ? true : false;
    }

    /**
     * 根据类型,授权id查询
     * @modify trainyao 2016-04-27 创建
     * @param  string   $oauthId   第三方平台授权id
     * @param  integer   $type      第三方授权类型
     * @return array                信息数组
     */
    public function getInfoByOauthType($oauthId, $type) {
        $option = array(
            'oauthid' => $oauthId,
            'type' => $type,
        );
        $data = $this->where($option)->find();
        return empty($data) ? array() : $data;
    }

    /**
     * 根据ID修改用户ID
     * @modify trainyao 2016-05-05 创建
     * @param  integer   $id        自增ID
     * @param  integer   $userId    用户ID
     * @return boolean                执行结果
     */
    public function saveUserId($id, $userId) {
        $option = array(
            'id' => $id,
            'isdelete' => NOT_DELETE,
        );
        $data = array(
            'userlogin_id' => $userId,
        );

        return $this->where($option)->save($data) === false ? false : true;
    }
}
